<template>
  <!-- 合同附件列表 -->
  <el-dialog
    v-el-drag-dialog
    title="合同附件列表"
    :visible.sync="visible"
    width="70%"
    min-width="1024px"
    append-to-body
    @close="reset"
  >
    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{bottomOffset:10}"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      :pagination="false"
      :total="tableData.total"
      custom-column
    />
  </el-dialog>
</template>

<script>
  import { queryEableContractTemplateDetail, queryEableContractUpdate } from '@/api'

  export default {
    name: 'affix-list',
    props: {
    },
    data() {
      return {
        visible: false,
        temp: {},
        tableData: {
          total: 0,
          data: [],
          column: [
            {
              prop: 'sourceName',
              label: '附件名称',
              render: (h, { row, $index }) => {
                return (
                  <div>
                    <el-link href={row.url} size='mini' target='_blank'>{row.sourceName}</el-link>
                  </div>
                )
              }
            },
            {
              label: '操作',
              align: 'center',
              fixed: 'right',
              render: (h, { row }) => {
                return (
                  <div>
                    <el-link size='mini' onClick={() => this.del(row)}>删除</el-link>
                  </div>
                )
              }
            }

          ]
        }
      }
    },
    created() {},
    methods: {
      async open(row) {
        this.temp = row
        const res = await queryEableContractTemplateDetail({ attachmentIds: row.attachmentIds })
        this.tableData.data = res.data
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 删除
      del(row) {
        this.$confirm(`您确定要删除此附件吗？`, '提示', {
          type: 'info'
        }).then(async() => {
          const { status } = await queryEableContractUpdate({
            contractId: this.temp.contractId,
            picId: row.id
          })
          if (status === 200) {
            this.$notify({
              title: '提示',
              message: `删除成功`,
              type: 'success',
              duration: 2000
            })
            const res = await queryEableContractTemplateDetail({ attachmentIds: this.temp.attachmentIds })
            this.tableData.data = res.data
            this.$emit('upDataTable')
          }
        })
      },
      reset() {
        this.visible = false
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
